using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UIMgr : MonoBehaviour
{
    public GameObject ctrlPanel;
    public GameObject timePanel;
    public GameObject resultPanel;


    public Image timerRender;
    public Sprite[] timerSpriteArr;

    public Text RemainText;
    public Text EatenText;
    public Text ScoreText;

    private int RemainNum;
    private int EatenNum;
    private int ScoreNum;


    public void CtrlPanelVisible(int idx)
    {
        ctrlPanel.SetActive(idx == 1);
        timePanel.SetActive(idx == 2);
        resultPanel.SetActive(idx == 3);
    }

    public void EatenDot()
    {
        RemainNum--;
        EatenNum++;
        ScoreNum += 100;
        UpdResultUI();
    }

    private void UpdResultUI()
    {
        RemainText.text = RemainNum.ToString();
        EatenText.text = EatenNum.ToString();
        ScoreText.text = ScoreNum.ToString();
    }
    public void OnQuitClick()
    {
        Application.Quit();
    }
    public void OnStartClick()
    {
        CtrlPanelVisible(2);
        StartCoroutine(PlayTimerAnimation());
    }
    IEnumerator PlayTimerAnimation()
    {
        for (int i = 0; i < timerSpriteArr.Length; i++)
        {
            timerRender.sprite = timerSpriteArr[i];
            yield return new WaitForSeconds(1f);
        }
        yield return new WaitForSeconds(1f);
        CtrlPanelVisible(3);
        GameMgr.Instance.StartGame();
    }

    void Start()
    {
        CtrlPanelVisible(1);
        int pacdotCount = GameObject.FindObjectsOfType<Pacdot>().Length;
        Debug.Log("Found " + pacdotCount + " Pacdot objects.");
        RemainNum = pacdotCount;
        EatenNum = 0;
        ScoreNum = 0;
        UpdResultUI();
    }

   
    void Update()
    {
        
    }
}
